/*
	COMMON API
	----------------------------------------------
	js
		Array.splice

		//表格数据序列化，反序列化
		//表格设置客户端数据
		var aa = grid.getData();
		var string = JSON.stringify(aa);
*/

/*
	NOTICE
	----------------------------------------------
	整个程序的划分
		环境
			数据
			逻辑部件
			当然数据可以独立存在，也可以内置在逻辑部件中。如果在逻辑部件中则受逻辑部件的管理，定义了三个管理方法，init,reset,close。
				init用于在刚开始的场景2中初始化数据
					有些数据或监听器，初始化一次就可以了，其他单据数据也可以使用，则不重置，写在init方法中
					有些数据或监听器，只当前单据数据使用，其他单据数据需要原始的环境，则需要重置，写在reset方法中，init方法在初始化时可以调用reset方法进行代码复用。 
				reset用于在场景3中，考虑到可能有上一张单据的数据，而重置逻辑部件中的数据和监听器等。
				close用于在关闭单据的场景中，销毁数据。

				数据的默认值在init方法中设置
				数据的编辑中值在场景3中设置
		场景
			代表真正的程序执行时机，在每一个时机中，会调用各个逻辑部件的方法，和操作数据，完成这个场景的功能。
			各个场景应该是严谨的，实现一个闭合的功能。
			数据的状态在各个场景的切换中变化，一直是合理的，不会出现未考虑过的数据状态。

			场景1，子表块在单据块的html中加载，执行子表块的builder.js代码，主要是定义上面那些数据和逻辑部件。
			场景2，单据块的builder.js中会获取所有子表块的对象，遍历，并调用所有子表块中builder.js中的回调对象的init方法，并传入BCP和表格序列化后的结构数据。
			场景3，单据显示出来后，调用新建或加载方法，获取表单业务数据，将各个子表的业务数据传给各个子表，进行显示，显示的时候经过格式化器进行处理。
			场景4，单据子表，操作过滤，排序，分页等按钮，对需要展示的数据进行变化，并刷新到子表上来，显示的时候经过格式化器进行处理。
			场景5，子表增行，删行，编辑单元格，同步数据到后端。
			场景6，子表接收到后端返回的服务器端变化量，并对各个逻辑部件中的数据进行更新，表格数据显示的时候经过格式化器进行处理。
			......

	场景中主要分为
		刷新后场景，各个部件中数据严谨一致，是一层一层从model到cacheData，再到h5表格数据计算同步出来的。
		编辑中场景，是编辑后，从服务器端传回来服务器变化量，然后同步到各个部件的数据中，不保证严谨一致，例如不符合过滤，排序，分页的规则。

	编辑中场景，包括获取位置和数据信息的操作，和修改位置和数据的操作，一定要先获取然后再修改，否则获取的信息不准，容易错位。

	缓存数据处理器的职责
		在刷新后场景，通过原始数据生成缓存数据
		在编辑中场景，维护缓存数据

	翻译处理器的职责
		只负责缓存数据和表格坐标的翻译
		所有涉及到计算，转换，翻译的操作，全部集中到这个处理器。因为这些操作是最容易出问题的环节，分散更不容易维护。
		这些操作可能不需要修改任何数据，只是做运算得出想要的结果
		其他修改数据的操作，还放在各自的处理器中。

	过滤处理器的职责
		通过维护一个过滤规则，或者一个过滤函数来对原始数据进行过滤，生成缓存数据。
		过滤规则的话，主要考虑后端有可能需要过滤，这样配置数据总比函数要好用。
		函数对象的话，主要考虑后端主要针对全部数据，可能不需要过滤，所以，这里直接用过滤函数。

	排序处理器的职责
		维护一个排序规则
		创建一个比较函数对已过滤的数据进行排序，生成缓存数据

	分页处理器的职责
		维护一个分页规则
		表格渲染时，通过对缓存数据进行分页，获取目标数据集合，进行显示。
		翻译处理器进行坐标计算的时候需要考虑分页。

	表格处理器的职责
		表格控件只负责显示和编辑部分子表数据的部分字段值。不支持子表相关的计算逻辑。
		并不存储完整的子表数据，很多字段都没有，连id字段都没有。
		表格控件只通过rowIndex,colIndex才能到缓存数据中找到对应的子表记录，进而进行业务处理。

	表格的结构
		0行	设计期使用	空,A,B,C
		0列	设计期使用	1			
						 2	 		 
						 3			 
		表头行区域，可以多行		  1列，序号列		  列从2开始
		浮动行						1列，序号列			列从2开始
		数据行						1列，序号列			列从2开始
			不分页，一直往下加
			分页，固定行数
		合计行						1列，序号列			列从2开始
			位置随数据行移动

	编辑器机制
		Grid.editCurrentCell
			负责整个编辑器的处理过程
		h5SubTable.h5TableProcessor.dataTypeEditor
			负责注册收集各个数据类型的编辑器实例
				一个编辑器实例
					内置了一个真实的dom元素
					内置了创建这个dom元素的函数
					内置了通过单元格数据给dom元素赋值的方法
					内置了返回dom元素的值给外部的方法
			负责创建一组grid编辑事件的监听器
				监听editorOpen事件，找到单元格对应的编辑器实例，用单元格的编辑值初始化编辑器的dom值；grid会将该dom放到表格容器中，这样才真正将dom放到了dom树中，方便第三方框架搜索到。
				监听editorShow事件，用于在显示时通过第三方js框架，将dom渲染成控件。
				监听editorClose事件，找到单元格对应的编辑器实例，获取编辑器的dom值，一般是给单元格赋值，但这里是设置editText的值，触发datachange事件，同步数据到后端，然后通过服务器端临时变化量给单元格赋值。
		h5SubTable.h5TableProcessor.renderCellData
			负责在渲染一个单元格时，根据单元格的数据的数据类型，注册编辑器ID，编辑器实例
		_initProcessorDatas
			负责在一开始，创建各个数据类型的编辑器实例，并创建各个编辑器实例的dom对象
			注册编辑器实例到h5SubTable.h5TableProcessor.dataTypeEditor
		dom元素必须绝对定位dom.style.position = 'absolute';
*/

{
    init : function(parentDom, callback){
		var h5SubTable = {};

		//---------------------------------------environment data and logic object-----------------------
		//init runtime context
		h5SubTable.parentDom = parentDom;
		h5SubTable.BCP = null;
		
		//metadata config data
		h5SubTable.kclass = null;//not use
		h5SubTable.bizType = {};//not use

		//缓存数据处理器
		//整体刷新和编辑表格是冲突的
		//增行和编辑单元格不应该触发整体刷新
		//删行也不应该触发整体刷新，因为有可能刚编辑过，如果刷新，可能编辑的行被刷没有了
		//增行，表格最后一行删除
		//删行，表格最后一行补充一行
		h5SubTable.cacheDataProcessor = {
			cacheDatas : null,
			init : function(){
				this.reset();
			},
			reset : function(){
				this.cacheDatas = [];
			},
			close : function(){
				delete this.cacheDatas;
			},
			buildCacheData : function(subDatas){
				var filterDatas = h5SubTable.filterProcessor.filter(subDatas);
				var sortDatas = h5SubTable.sortProcessor.sort(filterDatas);
				this.cacheDatas = sortDatas;
			},
			updateCacheDataFromInsertRow : function(isLastRow,isFirstRow,beforeDataId,subTableData){
				var beforeCacheDataIndex = -1;
				if(typeof beforeDataId != 'undefined' && beforeDataId != null){
					for(var i=0;i<this.cacheDatas.length;i++){
						var cacheData = this.cacheDatas[i];
						if(cacheData.id == beforeDataId){
							beforeCacheDataIndex= i+1;
							break;
						}
					}
				}else if(isLastRow){

				}else if(isFirstRow){
					beforeCacheDataIndex = 0;
				}

				this.cacheDatas.splice(beforeCacheDataIndex,0,subTableData);

				for(var i=0;i<this.cacheDatas.length;i++){
					var cacheData = this.cacheDatas[i];
					console.log(cacheData);
				}
			},
			updateCacheDataFromModifyCell : function(objectId,fieldName,value){
				for(var i=0;i<this.cacheDatas.length;i++){
					var cacheData = this.cacheDatas[i];
					if(cacheData.id == objectId){
						cacheData[fieldName] = value;
					}
				}
			},
			updateCacheDataFromDeleteRow : function(objectId){
				for(var i=0;i<this.cacheDatas.length;i++){
					var cacheData = this.cacheDatas[i];
					if(cacheData.id == objectId){
						this.cacheDatas.splice(i,1);
						break;
					}
				}

				for(var i=0;i<this.cacheDatas.length;i++){
					var cacheData = this.cacheDatas[i];
					console.log(cacheData);
				}
			}
		};
			
		//过滤处理器
		h5SubTable.filterProcessor = {
			filterFunctions : null,
			/*
			{
				subSzxFilter : function(subData){
					var result = true;
					if(subData['subSzx'] > 100){
						result = false;
					}
					return result;
				},
				subZfxFilter : function(subData){
					var result = true;
					if(subData['subZfx'].contains('hello')){
						result = false;
					}
					return result;
				},
			}
			*/
			init : function(){
				this.reset();
			},
			reset : function(){
				this.filterFunctions = {};
			},
			close : function(){
				delete this.filterFunctions;
			},
			registFilterFunction : function(name,filterFunction){
				this.filterFunctions[name] = filterFunction;
			},
			getFilterFunction : function(name){
				return this.filterFunctions[name];
			},
			deleteFilterFunction : function(name){
				delete this.filterFunctions[name];
			},
			filter : function(subDatas){
				var resultDatas = [];
				
				for(var i=0;i<subDatas.length;i++){
					var subData = subDatas[i];
					var isFiltered = false;
					
					for(var name in this.filterFunctions){
						var filterFunction = this.filterFunctions[name];

						var result = filterFunction.apply(window,[subData]);
						if(!result){
							isFiltered = true;
						}
					}
					
					if(!isFiltered){
						resultDatas.push(subData);
					}
				}
				
				return resultDatas;
			}
		};
		
		//排序处理器
		h5SubTable.sortProcessor = {
			sortRules : null,
			init : function(){
				this.reset();
			},
			reset : function(){
				this.sortRules = [];
			},
			close : function(){
				delete this.sortRules;
			},
			sort : function(subDatas){
				var resultDatas = subDatas.slice(0);
				var _sortRules = this.sortRules;
				resultDatas.sort(function(a,b){
					for(var i=0;i<_sortRules.length;i++){
						var sortRule = _sortRules[i];
						var aValue = a[sortRule.name];
						var bValue = b[sortRule.name];
						
						if(aValue == undefined){
							return -1;
						}
						
						if(bValue == undefined){
							return 1;
						}
						
						if(aValue == bValue){
							continue;
						}else if(sortRule.type == 'asc'){
							return aValue - bValue;
						}else {
							return bValue - aValue;
						}
					}
					
					return 0;
				});
				
				return resultDatas;
			}
		};
			
		//分页处理器
		h5SubTable.pagerProcessor = {
			pageControl : null, 
			pagerRule : null,
			init : function(){
				pageControl = parentDom.getElementsByClassName("page")[0];
				pageControl.style.maginTop = "5px";
				pageControl.style.minWidth = "800px";
				pageControl.style.minHeight = "20px";

				this.reset();

				//this.showPager();
			},
			reset : function(){
				this.pagerRule = {
					rowCountPerPage : 5,
					pageIndex : 0				//从0开始，分页控件上显示1
				};
			},
			close : function(){
				delete this.pageControl;
				delete this.pagerRule;
			},
			paginate : function(){
				if(h5SubTable.h5TableProcessor.isPage){
					var currentPageDatas = [];
					
					for(var i=0;i<h5SubTable.cacheDataProcessor.cacheDatas.length;i++){
						if(h5SubTable.translateProcessor.getBeforePageRowCount() <= i && i < h5SubTable.translateProcessor.getBeforePageRowCount() + this.pagerRule.rowCountPerPage){
							var subData = h5SubTable.cacheDataProcessor.cacheDatas[i];
							currentPageDatas.push(subData);
						}
					}
					
					return currentPageDatas;
				}else {
					return h5SubTable.cacheDataProcessor.cacheDatas;
				}
			},
			showPager : function(){
				if(h5SubTable.h5TableProcessor.isPage){
					laypage({
						cont: pageControl
						,skin: '#5FB878'
						,pages: h5SubTable.pagerProcessor.getPageCount()
						,curr:h5SubTable.pagerProcessor.getPageIndex() + 1//控件上的索引从1开始，程序中的从0开始
						//,groups:5
						//,first: true
						//,last: true
						//,prev:'上一页'
						//,next:'下一页'
						//,skip: true 
						,jump: function(obj, first){
							if(!first){
								h5SubTable.pagerProcessor.jumpToPage(obj.curr-1);//控件上的索引从1开始，程序中的从0开始
							}
						}
					});
				}
			},
			getPageCount : function(){
				var rowCount = h5SubTable.cacheDataProcessor.cacheDatas.length;

				if(0 == rowCount){
					return 1;
				}

				return Math.ceil(rowCount/this.pagerRule.rowCountPerPage);
			},
			getPageIndex : function(){
				return this.pagerRule.pageIndex;
			},
			jumpToPage : function(pageIndex){
				if(pageIndex<0 || pageIndex>this.getPageCount() - 1){
					return;
				}
				
				if(this.pagerRule.pageIndex != pageIndex){
					this.pagerRule.pageIndex = pageIndex;

					h5SubTable.subTableRefresh();
				}
			},
			modifyRowCountPerPage : function(newCount){
				if(newCount <= 0){
					return ;
				}

				this.pagerRule.rowCountPerPage = newCount;
				this.pagerRule.pageIndex = 0;

				h5SubTable.subTableRefresh();
			},
			afterInsertRow : function(index){
				if(h5SubTable.h5TableProcessor.isPage){
					if(h5SubTable.translateProcessor.getDataRowCount() > h5SubTable.pagerProcessor.pagerRule.rowCountPerPage){
						//如果不是最后一行，则删除最后一行
						if(index != h5SubTable.translateProcessor.getDataRowLastRow()-1){
							h5SubTable.h5TableProcessor.deleteRow((h5SubTable.translateProcessor.getDataStartRow()) + (h5SubTable.pagerProcessor.pagerRule.rowCountPerPage-1) + 1);//因为多了一行
						}else {
						//	h5SubTable.pagerProcessor.pagerRule.pageIndex++;
							h5SubTable.subTableRefresh();
						}
					}
				}
			},
			afterDeleteRow : function(index){
				if(h5SubTable.h5TableProcessor.isPage){
					if(h5SubTable.translateProcessor.getDataRowCount() < h5SubTable.pagerProcessor.pagerRule.rowCountPerPage){
						var lastRowIndex = h5SubTable.translateProcessor.getLastRowIndexForCurrentPage();
						h5SubTable.h5TableProcessor.insertRow(lastRowIndex);

						var nextSubData = h5SubTable.translateProcessor.getLastRowDataForCurrentPage();
						if(null != nextSubData){
							h5SubTable.h5TableProcessor.renderRowData(lastRowIndex,nextSubData);
						}
					}
				}
			},
			getPageOrder : function(order){
				if(h5SubTable.h5TableProcessor.isPage){
					return order + h5SubTable.translateProcessor.getBeforePageRowCount();
				}else {
					return order;
				}
			}
		};
			
			
			
			
			
			
			
			
			
			
			
		//缓存数据与h5表格的中间翻译处理器
		h5SubTable.translateProcessor = {
			init : function(){
				
			},
			reset : function(){
				
			},
			close : function(){
				
			},
			translateCacheDatasToh5TableData : function(){
				return h5SubTable.pagerProcessor.paginate();
			},
			translateRowIndexToObjectId : function(rowIndex){
				var cacheDataIndex = h5SubTable.translateProcessor.getBeforePageRowCount() + (rowIndex - h5SubTable.translateProcessor.getDataStartRow());
				var subData = h5SubTable.cacheDataProcessor.cacheDatas[cacheDataIndex];

				if(null == subData){
					return null;
				}

				return subData.id;
			},
			translateObjectIdToRowIndex : function(objectId){
				var cacheDataIndex = -1;
				for(var i=0;i<h5SubTable.cacheDataProcessor.cacheDatas.length;i++){
					var subData = h5SubTable.cacheDataProcessor.cacheDatas[i];
					if(subData.id == objectId){
						cacheDataIndex = i;
						break;
					}
				}
				
				var rowIndex = cacheDataIndex - (h5SubTable.translateProcessor.getBeforePageRowCount()) + (h5SubTable.translateProcessor.getDataStartRow());
				return rowIndex;
			},
			getSubDataByObjectId : function(objectId){
				for(var i=0;i<h5SubTable.cacheDataProcessor.cacheDatas.length;i++){
					var cacheData = h5SubTable.cacheDataProcessor.cacheDatas[i];
					if(cacheData.id == objectId){
						return cacheData;
					}
				}
				return null;
			},
			getLastRowDataForCurrentPage : function(){
				var cacheDataIndex = (h5SubTable.translateProcessor.getBeforePageRowCount()) + h5SubTable.pagerProcessor.pagerRule.rowCountPerPage - 1;
				return h5SubTable.cacheDataProcessor.cacheDatas[cacheDataIndex];
			},
			getLastRowIndexForCurrentPage : function(){
				var rowIndex =  (h5SubTable.translateProcessor.getDataStartRow()) + (h5SubTable.pagerProcessor.pagerRule.rowCountPerPage - 1);
				return rowIndex;
			},
			getBeforePageRowCount : function(){
				if(h5SubTable.h5TableProcessor.isPage){
					return h5SubTable.pagerProcessor.pagerRule.rowCountPerPage * h5SubTable.pagerProcessor.pagerRule.pageIndex;
				}else {
					return 0;
				}
			},
			getFieldMappingObjectByFieldName : function(fieldName){
				for(var i=0;i<h5SubTable.h5TableProcessor.fieldMapping.length;i++){
					var fm = h5SubTable.h5TableProcessor.fieldMapping[i];
					if(fm.name == fieldName){
						return fm;
					}
				}
				return null;
			},
			getFieldMappingObjectByColIndex : function(colIndex){
				for(var i=0;i<h5SubTable.h5TableProcessor.fieldMapping.length;i++){
					var fm = h5SubTable.h5TableProcessor.fieldMapping[i];
					if(fm.colIndex == colIndex){
						return fm;
					}
				}
				return null;
			},
			getShowTextByCell : function(colIndex,value){
				var fm = h5SubTable.translateProcessor.getFieldMappingObjectByColIndex(colIndex);
				var dataType = fm.type;
				var fomater = h5SubTable.h5TableProcessor.dataTypeFormater.getDataTypeFormater(dataType);
				var showText = fomater.apply({},[value]);
				return showText;
			},
			getDataStartRow : function(){
				return h5SubTable.h5TableProcessor.floatRowStartRow + 1;
			},
			getDataRowCount : function(){
				return h5SubTable.translateProcessor.getDataRowLastRow() - h5SubTable.translateProcessor.getDataStartRow() + 1;
			},
			getDataRowLastRow : function(){
				var dataLastRowIndex = h5SubTable.h5TableProcessor.grid.getRowCount()-1;
				if(h5SubTable.h5TableProcessor.isShowSum){
					dataLastRowIndex = dataLastRowIndex - 1;
				}
				return dataLastRowIndex;
			},
			getSumRowIndex : function(){
				return h5SubTable.h5TableProcessor.grid.getRowCount() + h5SubTable.h5TableProcessor.sumRowPosition;
			}
		};
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		//environment:h5 table operate
		/*
			Grid
				insertRows
				getRowCount
				setRowVisible
				isRowHidden
				
				
			Cell
				getClientData()
				setEditText(value,false);
				setShowText(text,true)//是否不触发事件
		*/
		h5SubTable.h5TableProcessor = {
			shell : null,
			grid : null,
			gridData : null,
			tableAttriName : null,//该表格对应的主表的属性名
			floatRowStartRow : 2, //浮动行起始行
			fieldMapping : null,  //浮动行字段映射
			firstRowForDesign : 0,//第0行，设计期使用，执行期隐藏
			firstColForDesign : 0,//第0列，设计期使用，执行期隐藏
			lastTitleRow : 1,	  //最后的标题行，用于定位序号文本
			orderCol : 1,		  //序号列
			isRendering : false,  //是否渲染中，渲染中不触发子表单元格数据同步
			isPage : false,		  //是否分页
			isShowSum : true,	  //是否显示合计
			sumRowPosition : -1,  //合计行位置，相对末尾的位置
			//isMultiSelect : false,
			//multiCheckCol : 2,
			containerMinWidth : -1,//父容器的最小宽度
			containerMinHeight : -1,//父容器的最小高度

			init : function(data){
				this.gridData = data;
				
				//create table
				shell = parentDom.getElementsByClassName("shell")[0];
				shell.style.minWidth = "800px";
				shell.style.minHeight = "200px";
				this.grid = new Grid(shell,this.gridData);

				this.parseConfigData();

				this.grid.setRowVisible(this.firstRowForDesign,false);
				this.grid.setColVisible(this.firstColForDesign,false);
				this.grid.setRowVisible(this.floatRowStartRow,false);
				this.grid.getCell(this.orderCol,this.lastTitleRow).setShowText("序号");
				this.grid.setSelectionMode(1);

				this.dataTypeFormater.init();
				this.dataTypeEditor.init();

				h5SubTable.h5TableProcessor.addListener('dataChange',this.dataChangeListener);
			},
			reset : function(){
				this.grid.reload(this.gridData);

				this.parseConfigData();
			
				this.grid.setRowVisible(this.firstRowForDesign,false);
				this.grid.setColVisible(this.firstColForDesign,false);
				this.grid.setRowVisible(this.floatRowStartRow,false);
				this.grid.getCell(this.orderCol,this.lastTitleRow).setShowText("序号");
				this.grid.setSelectionMode(1);

				this.dataTypeFormater.reset();
				this.dataTypeEditor.reset();
			},
			close : function(){
				delete this.grid;
				delete this.gridData;
				delete this.tableAttriName;
				delete this.floatRowStartRow;
				delete this.fieldMapping;

				this.dataTypeFormater.close();
				this.dataTypeEditor.close();
			},
			parseConfigData : function(){
				var clientData = this.grid.getClientData();
				this.tableAttriName = clientData["tableAttriName"];//$(parentDom).attr("tableattriname");//this.gridData.tableAttriName;//"subDatas";//parentDom.tableAttriName
				this.floatRowStartRow = clientData["floatRowStartRow"];//2;//this.gridData.floatRowStartRow;//$(parentDom).attr("floatRowStartRow");
				this.fieldMapping = [];
				/*
				this.fieldMapping = [
										{colIndex:'2',name:'subSzx',title:'数值型',type:'float'},
										{colIndex:'3',name:'subSzx',title:'整数型',type:'int'},
										{colIndex:'4',name:'subZfx',title:'字符型',type:'string'},
										{colIndex:'5',name:'subRqx',title:'日期型',type:'datetime'},
										{colIndex:'6',name:'subBex',title:'布尔型',type:'boolean'},
										{colIndex:'7',name:'subZjx',title:'字节型',type:'bytes'},
									];
				*/
				
				for(var i=0;i<this.grid.getColCount();i++){
					var cell = this.grid.getCell(i,this.floatRowStartRow);
					var clientData = cell.getClientData();
					var sublistAttr = clientData["sublistAttr"];
					if(sublistAttr){//{colIndex:'1',name:'subSzx',title:'数值型',type:'float'},
						var fieldInfo = {};
						fieldInfo["colIndex"] = i;
						fieldInfo["name"] = sublistAttr["name"];
						fieldInfo["title"] = sublistAttr["title"];
						fieldInfo["type"] = sublistAttr["type"];
						this.fieldMapping.push(fieldInfo);
					}
				}

				this.lastTitleRow = this.floatRowStartRow - 1;
				this.isPage = true;
				this.isShowSum = true;
				this.sumRowPosition = -1;

				this.containerMinWidth = $(shell.parentNode).width();
				this.containerMinHeight = $(shell.parentNode).height();
			},
			getSelectRow : function(){
				var selection = this.grid.getSelection();
				if(selection == null){
					return;
				}
				
				var rowIndex = selection.y;
				
				return rowIndex;
			},
			refresh : function(){
				var currentPageDatas = h5SubTable.translateProcessor.translateCacheDatasToh5TableData();
				
				this.clearRowData();

				for(var i=0;i<currentPageDatas.length;i++){
					var subData = currentPageDatas[i];
					
					this.insertRow(this.floatRowStartRow + 1 + i);
					this.renderRowData(this.floatRowStartRow + 1 + i,subData);
				}
				
				this.processOrder();
				this.processSumRow();
				this.processSubTableHeight();
			},
			clearRowData : function(){
				for(var i=h5SubTable.translateProcessor.getDataStartRow();i<h5SubTable.translateProcessor.getSumRowIndex();){
					this.deleteRow(i);
				}
			},
			renderRowData : function(rowIndex,subData){
				for(var i=0;i<this.fieldMapping.length;i++){
					var fm = this.fieldMapping[i];
					var colIndex = fm.colIndex;
					var name = fm.name;
					
					this.renderCellData(fm,rowIndex,colIndex,subData[name]);
				}
			},
			renderCellData : function(fm,rowIndex,colIndex,value){
				var dataType = fm.type;
				
				if(dataType == 'datetime'){
					value = value.replace('T',' ');
					value = value.replace('Z','');
				}

				var formater = this.dataTypeFormater.getDataTypeFormater(dataType);
				var showText = formater.apply({},[value]);
				
				console.log(colIndex + ',' + rowIndex + ',' + value);
				
				this.isRendering = true;
				this.grid.getCell(colIndex,rowIndex).setEditText(value,true);
				this.grid.getCell(colIndex,rowIndex).setShowText(showText,true);
				this.isRendering = false;

				var editor = this.dataTypeEditor.getDataTypeEditor(dataType);
				if(editor != null){
					this.grid.getCell(colIndex,rowIndex).setEditable(true);
					this.grid.getCell(colIndex,rowIndex).setEditorId(dataType);
					this.grid.getCell(colIndex,rowIndex).setEditor(editor.dom);
				}
			},
			processOrder : function(index){
				var order = 0;
				for(var i=0;i<this.grid.getRowCount();i++){
					if(i <= this.floatRowStartRow){
						continue;
					}
					if(this.grid.isRowHidden(i)){
						continue;
					}

					if(this.isShowSum && i == h5SubTable.translateProcessor.getSumRowIndex()){
						continue;
					}

					//this.grid.getCell(0,i).border = [1,1,1,1]
					order ++;
					this.grid.getCell(this.orderCol,i).setShowText(h5SubTable.pagerProcessor.getPageOrder(order),true);
				}
			},
			processSumRow : function(){
				if(this.isShowSum){
					var sumRowIndex = h5SubTable.translateProcessor.getSumRowIndex();
					this.grid.getCell(1,sumRowIndex).setShowText("合计",true);

					for(var i=0;i<this.fieldMapping.length;i++){
						var fm = this.fieldMapping[i];
						if(fm.type == 'float' || fm.type == 'int' || fm.type == 'double'){
							var sumValue = 0;

							for(var i=h5SubTable.translateProcessor.getDataStartRow();i<h5SubTable.translateProcessor.getSumRowIndex();i++){

								var value = this.grid.getCell(fm.colIndex,i).getEditText();
								if(value == null || value == ""){
									continue;
								}
								sumValue += parseFloat(value);
							}
							
							var showText = h5SubTable.translateProcessor.getShowTextByCell(fm.colIndex,sumValue);
							this.grid.getCell(fm.colIndex,sumRowIndex).setShowText(showText + "",true);
						}
					}
				}
			},
			processSubTableHeight : function(){
				var width = this.grid.getDataClientWidth();
				var height = this.grid.getDataClientHeight();//getHeight();

				if(width < this.containerMinWidth){
					width = this.containerMinWidth;
				}

				if(height < this.containerMinHeight){
					height = this.containerMinHeight;
				}

				this.grid.setSize(width,height);

				shell.parentNode.style.width = width+1 + "px";
				shell.parentNode.style.height = height+1 + "px";
			},
			insertRow : function(index){
				this.grid.insertRows(index,1,this.floatRowStartRow,2);
			},
			deleteRow : function(index){
				this.grid.deleteRows(index,1);
			},
			addListener : function(eventName,f){
				this.grid.addListener(eventName, f);
			},
			removeListener : function(eventName,f){
				this.grid.removeListener(eventName, f);
			},
			dataChangeListener : function(args){
				if(args.cause == 3){
					var rowIndex = args.rect.y;
					var colIndex = args.rect.x;
					
					//order
					if(colIndex == 0){
						return;
					}

					//todo
					if(!h5SubTable.h5TableProcessor.isRendering){	
						//非编辑区不触发TODO
						var objectId = h5SubTable.translateProcessor.translateRowIndexToObjectId(rowIndex);
						if(!objectId){
							return;
						}
						var fm = h5SubTable.translateProcessor.getFieldMappingObjectByColIndex(colIndex);
						var fieldValue = h5SubTable.h5TableProcessor.grid.getCell(colIndex,rowIndex).getEditText();
						
						var subData = h5SubTable.translateProcessor.getSubDataByObjectId(objectId);
						if(subData[fm.name] == fieldValue){
							return;
						}

						h5SubTable.updateSubTableAttribute(h5SubTable.h5TableProcessor.tableAttriName,objectId,fm.name,fieldValue);
					}
				}
			},
			dataTypeFormater : {
				formaters : null,
				init : function(){
					this.reset();
				},
				reset : function(){
					this.formaters = {};
					var defaultFormater = function(value){
						value = "v : " + value;
						return value;
					};
					h5SubTable.h5TableProcessor.dataTypeFormater.registDataTypeFormater("float",defaultFormater);
					h5SubTable.h5TableProcessor.dataTypeFormater.registDataTypeFormater("int",defaultFormater);
					h5SubTable.h5TableProcessor.dataTypeFormater.registDataTypeFormater("string",defaultFormater);
					h5SubTable.h5TableProcessor.dataTypeFormater.registDataTypeFormater("boolean",defaultFormater);
					h5SubTable.h5TableProcessor.dataTypeFormater.registDataTypeFormater("datetime",defaultFormater);
					h5SubTable.h5TableProcessor.dataTypeFormater.registDataTypeFormater("bytes",defaultFormater);
				},
				close : function(){
					delete this.formaters;
				},
				registDataTypeFormater : function(dataType,formater){
					this.formaters[dataType] = formater;
				},
				getDataTypeFormater : function(dataType){
					if(typeof this.formaters[dataType] == 'undefined'){
						return null;
					}else {
						return this.formaters[dataType];
					}
				}
			},
			dataTypeEditor : {
				editors : null,
				/*
					editors = {
							'float':{},
							'string':{}
						};

					editor = {
						dom : null,
						createDom : function(){
							if(!this.dom){
								this.dom = null;
							}
							return this.dom;
						},
						showEditor : function(event){//第三方框架初始化dom形成控件
							
						},
						initValueToDom : function(value){
							dom.value = value;
						},
						getValueFromDom : function(){
							return dom.value;
						}
					}
				*/
				init : function(){
					this.reset();
					/*
					h5SubTable.h5TableProcessor.grid.addListener("editorOpen",function(event){
						console.log("editorOpen : " + event);
						event.result.doit = 0;
						
					});
					*/

					/*
					h5SubTable.h5TableProcessor.grid.addListener("editorLocate",function(event){
						//console.log("editorLocate" + event);
						event.result.doit = 0;
						
					});
					*/

					/*
					h5SubTable.h5TableProcessor.grid.addListener("editorResize",function(event){
						//console.log("editorResize" + event);
						event.result.doit = 0;
						
					});
					*/

					h5SubTable.h5TableProcessor.grid.addListener("editorShow",function(event){
						//console.log("editorShow" + event);
						//event.result.doit = 0;

						var editorId = event.cell.cell.editorId;
						var value = event.cell.getEditText();
						event.cell.oldShowText = event.cell.getShowText();

						var editor = h5SubTable.h5TableProcessor.dataTypeEditor.getDataTypeEditor(editorId);
						editor.initValueToDom(value);
						if(editor.showEditor){
							editor.showEditor(event);
						}
					});

					/*
					h5SubTable.h5TableProcessor.grid.addListener("editorHide",function(event){
						//console.log("editorHide" + event);
						event.result.doit = 0;
					});
					*/

					h5SubTable.h5TableProcessor.grid.addListener("editorClose",function(event){
						console.log("editorClose" + event);
						event.result.doit = 0;

						var editorId = event.cell.cell.editorId;
						var editor = h5SubTable.h5TableProcessor.dataTypeEditor.getDataTypeEditor(editorId);
						var value = editor.getValueFromDom();

						//通过设置编辑文本，触发dataChange事件，同步数据到后端，然后通过处理服务器端变化量，重新渲染表格
						if(value != event.cell.getEditText()){
							event.cell.setEditText(value);
						}else {
							event.cell.setShowText(event.cell.oldShowText);
						}
					});
				},
				reset : function(){
					this.editors = {};

					var defaultDataTypeEditor = {
						dom:null,
						createDom : function(id){
							if(this.dom == null){
								var input = document.createElement('input');
								input.id = id || "default";
								input.style.position = "absolute";
								input.type = "text";
								this.dom = input;
							}
						},
						showEditor : function(event){

						},
						initValueToDom : function(value){
							this.dom.value = value;
						},
						getValueFromDom : function(){
							return this.dom.value;
						}
					};
					defaultDataTypeEditor.createDom();

					h5SubTable.h5TableProcessor.dataTypeEditor.registDataTypeEditor("float",defaultDataTypeEditor);
					h5SubTable.h5TableProcessor.dataTypeEditor.registDataTypeEditor("int",defaultDataTypeEditor);
					h5SubTable.h5TableProcessor.dataTypeEditor.registDataTypeEditor("string",defaultDataTypeEditor);
					h5SubTable.h5TableProcessor.dataTypeEditor.registDataTypeEditor("boolean",defaultDataTypeEditor);
					h5SubTable.h5TableProcessor.dataTypeEditor.registDataTypeEditor("datetime",defaultDataTypeEditor);
					h5SubTable.h5TableProcessor.dataTypeEditor.registDataTypeEditor("bytes",defaultDataTypeEditor);
				},
				close : function(){
					delete this.editors;
				},
				registDataTypeEditor : function(dataType,editor){
					this.editors[dataType] = editor;
				},
				getDataTypeEditor : function(dataType){
					if(typeof this.editors[dataType] == 'undefined'){
						return null;
					}else {
						return this.editors[dataType];
					}
				}
			}
		};











		//------------------------------------------------scence---------------------------------------------
		//场景1，渲染html元素时，定义环境中的数据和逻辑部件，场景的函数

		//场景2，打开单据时，创建子表块之后，机制JS代码，初始化单据对象bill.js，再执行子表块builder.js中的回调函数，开始初始化子表，此时还没有新建或加载单据数据，最后再执行表单js代码。
		h5SubTable.initSubTable = function(data,_BCP_){
			data = JSON.parse(data);
			h5SubTable.BCP = _BCP_;
			/*
			h5SubTable.BCP.registCustomEventListener("resetSubDatas",resetSubDatas);
			h5SubTable.BCP.registCustomEventListener("initSubDatas",initSubDatas);
			h5SubTable.BCP.registCustomEventListener("insertItem",insertItem);
			h5SubTable.BCP.registCustomEventListener("deleteItem",deleteItem);
			h5SubTable.BCP.registCustomEventListener("subTableProcessServerChangeInfo",subTableProcessServerChangeInfo);
			*/
			h5SubTable.h5TableProcessor.init(data);
			h5SubTable.cacheDataProcessor.init();
			h5SubTable.filterProcessor.init();
			h5SubTable.sortProcessor.init();
			h5SubTable.pagerProcessor.init();
			h5SubTable.translateProcessor.init();

			//init process
			//第一个注册事件的子表会先执行initSubDatas，会先把自己设置成当前子表，并设置当前子表数据条目id为该子表的第一行数据。
			h5SubTable.BCP.bill.h5SubTables.push(h5SubTable);
			if(null == h5SubTable.BCP.bill.currentH5SubTable){
				h5SubTable.BCP.bill.currentH5SubTable = h5SubTable;
			}
			$(h5SubTable.parentDom).on("click",function(){
				//第一个注册事件的子表会先执行initSubDatas，会先把自己设置成当前子表。
				h5SubTable.BCP.bill.currentH5SubTable = h5SubTable;
			});
		};
		
		//场景3， 已打开单据，但需要加载另一个单据时调用，用于重置子表
		h5SubTable.resetSubDatas = function(){
			h5SubTable.h5TableProcessor.reset();
			h5SubTable.cacheDataProcessor.reset();
			h5SubTable.filterProcessor.reset();
			h5SubTable.sortProcessor.reset();
			h5SubTable.pagerProcessor.reset();
			h5SubTable.translateProcessor.reset();
			
			h5SubTable._processorOutSetDatas();
		};

		//场景3， 不管是新单据，还是加载另一个单据，在点击新建，或加载数据后调用，给子表赋值。
		h5SubTable.initSubDatas = function(){
			//如果没有子表数据，初始化子表数据结构
			var model = h5SubTable.BCP.getModel();
			if(typeof model[h5SubTable.h5TableProcessor.tableAttriName] == 'undefined' || model[h5SubTable.h5TableProcessor.tableAttriName] == null){
				model[h5SubTable.h5TableProcessor.tableAttriName] = [];
				h5SubTable.BCP.setModel(model);
			}

			h5SubTable.subTableRefresh();
		};

		//外部初始化
		h5SubTable._processorOutSetDatas = function(){
			h5SubTable.filterProcessor.registFilterFunction('subSzxFilter',function(subData){
				var result = true;
				if(subData['subSzx'] > 100){
					result = false;
				}
				return result;
			});
			h5SubTable.filterProcessor.registFilterFunction('subZfxFilter',function(subData){
				var result = true;
				if(subData['subZfx'].indexOf('k') != -1){
					result = false;
				}
				return result;
			});
			
			h5SubTable.sortProcessor.sortRules = [
					{name:'subSzx',type:'asc'},
					{name:'subZfx',type:'desc'}
				];

			h5SubTable.pagerProcessor.pagerRule = {
				rowCountPerPage : 5,
				pageIndex : 0
			};
			
			var datatimeFormater = function(value){
				if(!value){
					value = '';
				}
				value = "v : " + value.substring(0,10);

				return value;
			};
			h5SubTable.h5TableProcessor.dataTypeFormater.registDataTypeFormater("datetime",datatimeFormater);

			var datetimeDataTypeEditor = {
				dom:null,
				createDom : function(id){
					if(this.dom == null){
						var input = document.createElement('input');
						input.id = id || "datetime";
						input.classList.add(id);
						input.style.position = "absolute";
						input.type = "text";
						this.dom = input;
					}
				},
				showEditor : function(event){
					laydate.skin('yalan');
					laydate({
						elem: '#' + this.dom.id,
						format: 'YYYY-MM-DD hh:mm:ss', // 分隔符可以任意定义，该例子表示只显示年月
						festival: true, //显示节日
						istime: true,
						isclear:false,
						issure:false,
						istoday: false,
						dom:this.dom,
						choose: function(datas){ //选择日期完毕的回调
							this.dom.value = datas;
						}
					});
				},
				initValueToDom : function(value){
					this.dom.value = value;
				},
				getValueFromDom : function(){
					return this.dom.value;
				}
				
			};
			datetimeDataTypeEditor.createDom();
			h5SubTable.h5TableProcessor.dataTypeEditor.registDataTypeEditor("datetime",datetimeDataTypeEditor);
		};

		h5SubTable.subTableRefresh = function(){
			var resultObject = h5SubTable.BCP.getModel();
			if(typeof resultObject[h5SubTable.h5TableProcessor.tableAttriName] != 'undefined'){
				var subDatas =  resultObject[h5SubTable.h5TableProcessor.tableAttriName];
				if(subDatas){
					h5SubTable.cacheDataProcessor.buildCacheData(subDatas);
					h5SubTable.h5TableProcessor.refresh();
				}
			}

			h5SubTable.pagerProcessor.showPager();
		};
		
		//过滤

		//排序

		//分页
			
		//scence:edit data and synchroniz
		h5SubTable.insertItem = function(){
			var selectId = h5SubTable.h5TableProcessor.getSelectRow();
			if(selectId != null){
				var objectId = h5SubTable.translateProcessor.translateRowIndexToObjectId(selectId);
				if(typeof objectId != 'undefined' && objectId != null){
					h5SubTable._insertItem(h5SubTable.h5TableProcessor.tableAttriName,"false","false",objectId);
					return;
				}
			}
			
			h5SubTable._insertItem(h5SubTable.h5TableProcessor.tableAttriName,"false","true","");
		};
		
		h5SubTable._insertItem = function(mainAttriName,isLastRow,isFirstRow,subDataId){
			var obj = {
				runtimeId:h5SubTable.BCP.bill.runtimeId,
				methodParameters: [mainAttriName,isLastRow,isFirstRow,subDataId]
			};
			h5SubTable.BCP.invokeBizMethod("insertItem",obj,function(data){
				var responseObject = JSON.parse(data);
				h5SubTable.BCP.bill.runtimeId = responseObject.runtimeId;
				
				if(responseObject.status == 'success'){
					var result = responseObject.result;
					var serverChangeInfo = JSON.parse(responseObject.serverChangeInfo);
					
					/*
					var serverChangeInfo = [
						{
							"changeType":"SubInsertRowChangeItem",
							"isLastRow":"true",
							"isFirstRow":"false",
							"beforeDataId":"",
							"data":"{\"_type\":\"com.beecode.bap.biztrait.type.SubTable1\",\"subSzx\":1.0,\"subZfx\":\"a\",\"id\":\"552addfe-b6e1-4c0f-99e1-63ddc17bf90e\",\"mid\":\"e6b0e22a-678e-446f-96b8-6b50cd390016\",\"ordinal\":0}",
							"mainAttriName":"subChildrens1"
						}
					]*/
					//processServerChangeInfo(serverChangeInfo);
					
					h5SubTable.BCP.bill.processServerChangeInfo(serverChangeInfo);
				}else if(responseObject.status == 'programException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'businessException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'validateErrorException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'validateAlertException'){
					var message = responseObject.result;
					alert(message);
				}
			});
				
		};
		
		h5SubTable.deleteItem = function(){
			var selectId = h5SubTable.h5TableProcessor.getSelectRow();
			if(selectId == null){
				alert("请选择一个要删除的行！");
				return;
			}
			
			var objectId = h5SubTable.translateProcessor.translateRowIndexToObjectId(selectId);
			if(null != objectId){
				h5SubTable._deleteItem(h5SubTable.h5TableProcessor.tableAttriName,objectId);
			}
		};
		
		h5SubTable._deleteItem = function(mainAttriName,subDataId){
			var obj = {
				runtimeId:h5SubTable.BCP.bill.runtimeId,
				methodParameters: [mainAttriName,subDataId]
			};
			h5SubTable.BCP.invokeBizMethod("deleteItem",obj,function(data){
				var responseObject = JSON.parse(data);
				h5SubTable.BCP.bill.runtimeId = responseObject.runtimeId;
				
				if(responseObject.status == 'success'){
					var result = responseObject.result;
					var serverChangeInfo = JSON.parse(responseObject.serverChangeInfo);
					
					/*
					var serverChangeInfo = [
						{
							"changeType":"SubDeleteRowChangeItem",
							"subDataId":"552addfe-b6e1-4c0f-99e1-63ddc17bf90e",
							"mainAttriName":"subChildrens1"
						}
					]
					*/
					//processServerChangeInfo(serverChangeInfo);
					
					h5SubTable.BCP.bill.processServerChangeInfo(serverChangeInfo);
				}else if(responseObject.status == 'programException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'businessException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'validateErrorException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'validateAlertException'){
					var message = responseObject.result;
					alert(message);
				}
			});
		};
		
		h5SubTable.updateSubTableAttribute = function(mainAttriName,subDataId,subAttriName,attriValue){
			var obj = {
				runtimeId:h5SubTable.BCP.bill.runtimeId,
				methodParameters: [mainAttriName,subDataId,subAttriName,attriValue]
			};
			h5SubTable.BCP.invokeBizMethod("updateSubTableAttribute",obj,function(data){
				var responseObject = JSON.parse(data);
				h5SubTable.BCP.bill.runtimeId = responseObject.runtimeId;
				
				if(responseObject.status == 'success'){
					var result = responseObject.result;
					var serverChangeInfo = JSON.parse(responseObject.serverChangeInfo);
					
					/*
					var serverChangeInfo = [
						{"changeType":"SubAttributeChangeItem","subDataId":"552addfe-b6e1-4c0f-99e1-63ddc17bf90e","subAttriName":"subZfx","mainAttriName":"subChildrens1","subAttriValue":"hello"}
					]
					*/
					//processServerChangeInfo(serverChangeInfo);
					
					h5SubTable.BCP.bill.processServerChangeInfo(serverChangeInfo);
				}else if(responseObject.status == 'programException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'businessException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'validateErrorException'){
					var message = responseObject.result;
					alert(message);
				}else if(responseObject.status == 'validateAlertException'){
					var message = responseObject.result;
					alert(message);
				}
			});
		};
		
		h5SubTable.subTableProcessServerChangeInfo = function(serverChangeInfo){
			for(var index=0;index<serverChangeInfo.length;index++){
				var serverChangeInfoItem = serverChangeInfo[index];
				
				if(serverChangeInfoItem.changeType == 'SubInsertRowChangeItem'){
					if(serverChangeInfoItem.mainAttriName == h5SubTable.h5TableProcessor.tableAttriName){					
						var isLastRow = serverChangeInfoItem.isLastRow;
						var isFirstRow = serverChangeInfoItem.isFirstRow;
						var beforeDataId = serverChangeInfoItem.beforeDataId;
						var subData = JSON.parse(serverChangeInfoItem.data);					
						if(serverChangeInfoItem.mainAttriName == h5SubTable.h5TableProcessor.tableAttriName){
							var subTableData = subData;//getSubTableDataByMappingAndSubData(colMapping,subData);
							
							//1. modelData修改
							var model = h5SubTable.BCP.getModel();
							model[h5SubTable.h5TableProcessor.tableAttriName].push(subTableData);

							//2. cacheData修改
							h5SubTable.cacheDataProcessor.updateCacheDataFromInsertRow(isLastRow,isFirstRow,beforeDataId,subTableData);
							
							//3. h5Table修改
							var insertRowIndex = -1;
							if(isLastRow){

							}else if(isFirstRow){
								insertRowIndex = h5SubTable.h5TableProcessor.floatRowStartRow + 1;
							}else if(beforeDataId){
								var beforeDataIndex = h5SubTable.translateProcessor.translateObjectIdToRowIndex(beforeDataId);
								insertRowIndex = beforeDataIndex + 1;
							}

							h5SubTable.h5TableProcessor.insertRow(insertRowIndex);//往后+1，占用的是那一行
							h5SubTable.h5TableProcessor.renderRowData(insertRowIndex,subTableData);
							h5SubTable.pagerProcessor.afterInsertRow(insertRowIndex);
							h5SubTable.h5TableProcessor.processOrder();
							h5SubTable.h5TableProcessor.processSumRow();
							h5SubTable.h5TableProcessor.processSubTableHeight();

							//4. 其他控件修改
							h5SubTable.pagerProcessor.showPager();
						}
					}
				}else if(serverChangeInfoItem.changeType == 'SubAttributeChangeItem'){
					if(serverChangeInfoItem.mainAttriName == h5SubTable.h5TableProcessor.tableAttriName){
						var subDataId = serverChangeInfoItem.subDataId;
						
						//1. 修改modelData
						var model = h5SubTable.BCP.getModel();
						var subDatas = model[h5SubTable.h5TableProcessor.tableAttriName];
						for(var i=0;i<subDatas.length;i++){
							if(subDatas[i].id == subDataId){
								var subData = subDatas[i];
								subData[serverChangeInfoItem.subAttriName] = serverChangeInfoItem.subAttriValue;
								break;
							}
						}

						//2. 修改cacheData
						
						//3. 修改表格单元格
						var fm = h5SubTable.translateProcessor.getFieldMappingObjectByFieldName(serverChangeInfoItem.subAttriName);
						if(null == fm){
							continue;
						}

						var rowIndex = h5SubTable.translateProcessor.translateObjectIdToRowIndex(subDataId);
						h5SubTable.h5TableProcessor.renderCellData(fm,rowIndex,fm.colIndex,serverChangeInfoItem.subAttriValue);
						h5SubTable.h5TableProcessor.processSumRow();

						//4. 其他控件修改
					}
				}else if(serverChangeInfoItem.changeType == 'SubDeleteRowChangeItem'){
					if(serverChangeInfoItem.mainAttriName == h5SubTable.h5TableProcessor.tableAttriName){
						var subDataId = serverChangeInfoItem.subDataId;
						var subDataIndex = h5SubTable.translateProcessor.translateObjectIdToRowIndex(subDataId);

						//1. modelData修改
						var model = h5SubTable.BCP.getModel();
						var subDatas = model[h5SubTable.h5TableProcessor.tableAttriName];
						for(var i=0;i<subDatas.length;i++){
							var subData = subDatas[i];
							if(subData.id == subDataId){
								subDatas.splice(i,1);
								break;
							}
						}

						//2. cacheData修改
						h5SubTable.cacheDataProcessor.updateCacheDataFromDeleteRow(subDataId);

						//3. h5Table修改
						h5SubTable.h5TableProcessor.deleteRow(subDataIndex);
						h5SubTable.pagerProcessor.afterDeleteRow(subDataIndex);
						h5SubTable.h5TableProcessor.processOrder();
						h5SubTable.h5TableProcessor.processSumRow();
						h5SubTable.h5TableProcessor.processSubTableHeight();

						//4. 其他控件修改
						h5SubTable.pagerProcessor.showPager();
					}
				}
			}
		};


















        callback(
			//单据块的builder.js会调用该回调对象的init方法，并传入BCP和data
			{
				init:function(data,_BCP_){
					/*
						这个过程是根据序列化的数据，反序列化出来表格控件。
						创建表格时不传入options数据。
						调用反序列化接口时，传入整个数据。
						反序列化会还原options中的内容，包括列信息
						反序列化会还原dom 元素的内容
						反序列化会还原dom 元素上的options中的列信息
						反序列化会还原事件监听
						不需要调用initTable
					*/
					/**
					var data = 
					{
						thisstyle: "width: 530px; overflow: hidden; text-align: center; padding: 0px; position: static;", 
						parentstyle: "text-align: left; overflow-x: scroll; border-left: 1px solid rgb(234, 234, 234);", 
						sumhtml: "<div style=\"width:100%;height:37px;float:left;background:#f6f6f6;border:1px solid #eaeaea;line-height:37px;border-left:0px;\" class=\"tableth\"><div style=\"float:left;width:50px;height:35px; background:#f6f6f6\" class=\"checkboxth\"><input type=\"checkbox\" class=\"checkboxthinput\"></div><div style=\"float:left;width:58px;height:35px; background:#f6f6f6\" class=\"indexth\">序号</div><div style=\"float:left;width:140px;height:37px; \" class=\"th0 subSzxth zctablethtd\" i=\"0\">数值型</div><div style=\"float:left;width:140px;height:37px;\" class=\"th1 subZfxth zctablethtd\" i=\"1\">字符型</div><div style=\"float:left;width:140px;height:37px;\" class=\"th2 idth zctablethtd\" i=\"2\">ID</div></div><div tdbackgroundcolor=\"#FFFFFF\" style=\"width:100%;height:37px;float:left;background:#FFFFFF;line-height:37px;display:none;border-bottom:1px solid #eaeaea;border-left:0px; border-left:1px solid #eaeaea;border-right:1px solid #eaeaea;border-left:0px;\" class=\"tabletr0 zctabletr hidezctabletr\" oddbackgroundcolor=\"#FFFFFF\" evenbackgroundcolor=\"#EBEBEB\"><div style=\"float:left;width:50px;height:36px;\" class=\"checkboxtr\"><input type=\"checkbox\" class=\"checkboxtrinput\"></div><div style=\"float:left;width:58px;height:36px; \" class=\"indextr\">0</div><div style=\"float: left; width: 140px; height: 37px; margin-left: 0px; cursor: pointer;\" class=\"tr3 subSzxtd zctabletd create_table_Edit\" i=\"0\" classname=\"subSzx\">subSzx</div><div style=\"float: left; width: 140px; height: 37px; cursor: pointer;\" class=\"tr3 subZfxtd zctabletd create_table_Edit\" i=\"1\" classname=\"subZfx\">subZfx</div><div style=\"float: left; width: 140px; height: 37px; cursor: pointer;\" class=\"tr3 idtd zctabletd create_table_Edit TABLE_ID_COL\" i=\"2\" classname=\"id\">id</div></div><div style=\"width:100%;height:50px;float:left;\" class=\"zctable_page_html\"><div class=\"zctable_page\" style=\"width:100%;position:absolute;\"><ul class=\"pagination\" style=\"margin:0px;\"></ul></div></div>"
					};**/
					/*
					data = {
						options: {
							loadMode: 1,
							loadByRow: true,
							selectionMode: 3,
							// editMode: Const.EDIT_MODE_EDIT,
							editMode: 2,
							enterNext: 4,
							rowSelectable: true,
							colSelectable: false,
							ignoreHidden: true,
							colResizeable: true,
							rowResizeable: true,
							colFreeResizeable: true,
							rowFreeResizeable: true,
							colGrabable: true,
							showSelectionBorder: true,
							currentCellBorderHidden: true,
							colExchangeable: false,
							passReadOnly: true,
							showSelectionChange: false,
							selectionColor: 'rgba(255,0,0,0.2)',
							selectionBorderColor: 'rgba(0,255,0,1)',
							selectionBorderWidth: 3,
							currentCellColor: 'rgba(255,255,0,0.1)',
							currentCellBorderColor: null,
							mergeCellShowMode: 1
						},
						cells: {
							rowList: null
						},
						mergeCells: [
							//{ col: 2, row: 3, width: 3, height: 3 }
							//{col:0,row:6,width:3,height:1},
							//{col:1,row:7,width:2,height:1},
							//{col:2,row:8,width:2,height:1},
							//{col:3,row:9,width:3,height:1},
							//{col:4,row:10,width:2,height:1},
							//{col:5,row:11,width:2,height:1},
						],
						rows: [],
						cols: [],
						colHeaderCount: 0,
						rowHeaderCount: 0,
						colFooterCount: 0,
						rowFooterCount: 0,
						defaultEditorId: null,
						rowCount: 3,
						colCount: 7,
						width: 80 * 10 + 100,
						height: 40 * 30,
						defalutFont: {
							fontName: 'Times New Roman',
							fontSize: '20px',
							fontStyle: 'italic',
							foregroundColor: '#f00',
							textStroke: true,
							textShadow: {
								offsetX: 4,
								offsetY: 4,
								blur: 2,
								color: '#020'
							}
						}
					};

					function createInput() {
						var input = document.createElement('input');
						input.type = "button";
						return input;
					}

					function createCellModel(x, y) {
						return {
							colIndex: y,
							rowIndex: x,
							editorId: 'default',
							title: 'title',
							//showImage: 'image',
							showText: '',
							editText: '',
							selectable: true,
							editable: true,
							cellMode: 1,
							html: '<span>what what what what what what what what what what</span>',
							control: createInput(),
						// treeImage: '',
							checked: null,
							checkable: true,
							expandable: true,
							expanded: null,
							depth: 0,
							clientData: null,
							isTreeEnd: false,

							rowSpan: 1,
							colSpan: 1,
							isMerged: false,



							backStyle: 1,
						// backColor: '#4a1',
				
				//			gradientBackground: {
				//				begin: 'rgb(100,100,200)',
				//				end: 'rgb(100,200,200)',
				//				direction: Cell.DIRECTION_HORIZ
				//			},
				
							border: [1, 1],
							borderColor: ['#550', '#055', '#00f', '#0ff'],

							fontName: '宋体',
							//fontStyle
							fontSize: 12,
							fontBold: false,
							fontItalic: false,
							fontColor: '#000',
							textStroke: null,
							textShadow: {
								offsetX: 0,
								offsetY: 0,
								blur: 0,
								color: '#00f'
							},
							wrapLine: false,
							indent: 0,
							horzAlign: 3,
							vertAlign: 0,
							vertText: false,
							fitFontSize: true,
							multiLine: true,
							// decoration: TextStyle.DECORATION_STRIKEOUT

							// style: {
							// back: {
							// backStyle: null,
							// backColor: '#4a1',
							// gradientBacground: {
							// begin: 'rgb(100,100,200)',
							// end: 'rgb(100,200,200)',
							// direction: Cell.DIRECTION_HORIZ
							// }
							// },
							// image: {
							// backImage: 'image/app-store.png',
							// backImageStyle: Const.BACK_IMAGE_STYLE_BOUNDS,
							// backImageHorizion: 2,
							// backImageVertical: 2,
							// backImageBounds: {'x':0,'y':20,'width':50,'height':50}
							// },
							// border: [1,1],
							// borderColor: ['#550','#055','#00f','#0ff'],
							//
							// fontName: '宋体',
							// fontSize: 12,
							// fontBold: false,
							// fontItalic: false,
							// fontColor: '#000',
							// textStroke: null,
							// textShadow: {
							// offsetX: 0,
							// offsetY: 0,
							// blur: 0,
							// color: '#00f'
							// },
							// wrapLine: false,
							// indent: 0,
							// horzAlign: 0,
							// vertAlign: 0,
							// vertText: false,
							// fitFontSize: true,
							// multiLine:true,
							// decoration: TextStyle.DECORATION_STRIKEOUT
							// },
						};
					}

					var cellLists = [];
					var cellList;
					var cell;

					for (var i = 0; i < data.rowCount; i++) {
						cellList = [];
						for (var j = 0; j < data.colCount; j++) {
							cell = createCellModel(i, j);

							cellList.push(cell);
						}
						cellLists[i] = cellList;
					}

					data.cells.rowList = cellLists;
					
					data.cells.rowList[1][2].selectable = true;
					data.cells.rowList[1][2].showText = '数值型';
					data.cells.rowList[1][2].editText = '数值型';
					data.cells.rowList[1][3].selectable = true;
					data.cells.rowList[1][3].showText = '字符型';
					data.cells.rowList[1][3].editText = '字符型';
					data.cells.rowList[1][4].selectable = true;
					data.cells.rowList[1][4].showText = '日期型';
					data.cells.rowList[1][4].editText = '日期型';
					data.cells.rowList[1][5].selectable = true;
					data.cells.rowList[1][5].showText = '布尔型';
					data.cells.rowList[1][5].editText = '布尔型';
					data.cells.rowList[1][6].selectable = true;
					data.cells.rowList[1][6].showText = '字节型';
					data.cells.rowList[1][6].editText = '字节型';
					
					data.cells.rowList[2][2].showText = 'subSzx';
					data.cells.rowList[2][2].editText = 'subSzx';
					data.cells.rowList[2][2].editable = true;
					data.cells.rowList[2][2].selectable = true;
					data.cells.rowList[2][3].showText = 'subZfx';
					data.cells.rowList[2][3].editText = 'subZfx';
					data.cells.rowList[2][3].editable = true;
					data.cells.rowList[2][3].selectable = true;
					data.cells.rowList[2][4].showText = 'subRqx';
					data.cells.rowList[2][4].editText = 'subRqx';
					data.cells.rowList[2][4].editable = true;
					data.cells.rowList[2][4].selectable = true;
					data.cells.rowList[2][5].showText = 'subBex';
					data.cells.rowList[2][5].editText = 'subBex';
					data.cells.rowList[2][5].editable = true;
					data.cells.rowList[2][5].selectable = true;
					data.cells.rowList[2][6].showText = 'subZjx';
					data.cells.rowList[2][6].editText = 'subZjx';
					data.cells.rowList[2][6].editable = true;
					data.cells.rowList[2][6].selectable = true;

					data.cells.rowList[2][2].clientData = {
						"fieldInfo" : {colIndex:'2',name:'subSzx',title:'数值型',type:'float'}
					};
					data.cells.rowList[2][3].clientData = {
						"fieldInfo" : {colIndex:'3',name:'subZfx',title:'字符型',type:'string'}
					};
					data.cells.rowList[2][4].clientData = {
						"fieldInfo" : {colIndex:'4',name:'subRqx',title:'日期型',type:'datetime'}
					};
					data.cells.rowList[2][5].clientData = {
						"fieldInfo" : {colIndex:'5',name:'subBex',title:'布尔型',type:'boolean'}
					};
					data.cells.rowList[2][6].clientData = {
						"fieldInfo" : {colIndex:'6',name:'subZjx',title:'字节型',type:'bytes'}
					};

					function createRowModel(value) {
						return {
							size: value,
							auto: false,
							hidden: false,
							//hintSize就是数据中的大小
							clientSize: value
						};
					}
					
					var rows = [];
					var row;
					for (var i = 0; i < data.rowCount; i++) {
						row = createRowModel(40);
						rows.push(row);
					}
					data.rows = rows;

					var cols = [];
					var col;
					for (var i = 0; i < data.colCount; i++) {
						col = createRowModel(100);
						cols.push(col);
					}
					data.cols = cols;
*/
					h5SubTable.initSubTable(data,_BCP_);
				}
			}
		);
    }
}